import { createRouter, createWebHistory,type RouteRecordRaw } from 'vue-router';

// 建议使用懒加载导入视图组件，以优化初始加载时间
// import StoreFront from '../views/StoreFront.vue'; // 如果不使用懒加载
// import AdminProductManagement from '../views/admin.vue'; // 如果不使用懒加载

const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'StoreFront',
        // component: StoreFront, // 非懒加载
        component: () => import('../views/StoreFront.vue') // 懒加载 (推荐)
        // 确保你已将原 App.vue 内容移至此路径
    },
    {
        path: '/profile',
        name: 'Profile',
        component: () => import('../views/Profile.vue'),
        meta: { title: '个人信息' }
    },
    {
        path: '/admin',
        name: 'Admin',
        component: () => import('../views/admin.vue'), // 这是新的布局组件
        redirect: '/admin/dashboard', // 默认重定向到仪表盘
        children: [
            {
                path: 'dashboard',
                name: 'AdminDashboard',
                component: () => import('../views/admin/AdminDashboard.vue'),
            },
            {
                path: 'products',
                name: 'AdminProductManagement',
                component: () => import('../views/admin/ProductManagement.vue'),
            },
            {
                path: 'users',
                name: 'AdminUserManagement',
                component: () => import('../views/admin/UserManagement.vue'),
            },
            {
                path: 'orders',
                name: 'AdminOrderManagement',
                component: () => import('../views/admin/OrderManagement.vue'),
            },
            {
                path: 'shipping',
                name: 'AdminShippingManagement',
                component: () => import('../views/admin/ShippingManagement.vue'),
            }
        ]
    },
    {
        path: '/product/:id',
        name: 'ProductDetail',
        component: () => import('../views/ProductDetail.vue'),
        props: true
    },
    // 你可以在这里添加更多的路由
];

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL), // Vite 项目通常使用 import.meta.env.BASE_URL
    routes,
});

export default router;